Fix Poetry venv discovery to match Poetry (#327, #329) - #330
Merged
Mikola Lysenko (mikolalysenko) merged 4 commits intoOct 1, 2026
Merged
Conversation
Assisted-by: Claude Code:claude-opus-5-5
This was referenced Sep 30, 2026
Agent mode missed the virtualenv Poetry installed into for nameless package-mode = false projects, Poetry 2 projects naming both [project] and [tool.poetry], projects with in-project = false next to a stray .venv, and every project on Windows. The scan then skipped the patch and exited 0. Pick the env name in poetry-core's order ([project].name, then [tool.poetry].name, then non-package-mode), honour an explicit in-project setting before ./.venv, and drop the \\?\ prefix before hashing the cwd on Windows. Fixes #327 Fixes #329 Assisted-by: Claude Code:claude-opus-5-5
Mikola Lysenko (mikolalysenko)
marked this pull request as ready for review
September 30, 2026 15:59
Collaborator
Author
|
BugBot review Generated by Claude Code |
This was referenced Sep 30, 2026
Resolve conflicts with #277: keep Poetry-aware venv probe order in find_local_venv_site_packages and add the Poetry entry to the consolidated changelog. Assisted-by: Claude Code:claude-opus-5-5
Collaborator
Author
|
BugBot review Generated by Claude Code |
Collaborator
Author
|
[burn-down agent] Ready for review on Generated by Claude Code |
Mikola Lysenko (mikolalysenko)
enabled auto-merge (squash)
October 1, 2026 03:14
Tanmay Singla (Tanmay182003)
approved these changes
Oct 1, 2026
Union the CHANGELOG Fixed entries from both sides. Co-Authored-By: Claude <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko)
deleted the
agent/fix-poetry-venv-discovery
branch
October 1, 2026 13:27
Collaborator
Author
|
bugbot run Generated by Claude Code |
Mikola Lysenko (mikolalysenko)
pushed a commit
that referenced
this pull request
Oct 1, 2026
Keeps both CHANGELOG entries (gem manifest fix and the Poetry venv fix from #330). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6i4cQ51yarBFnFs2b8HRx
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 50cde0a. Configure here.
Mikola Lysenko (mikolalysenko)
pushed a commit
that referenced
this pull request
Oct 1, 2026
#330 reordered Poetry venv discovery in the same function. Keep both: a Pipenv project uses only the venv Pipenv resolves, then Poetry's out-of-tree env when Poetry would not use ./.venv, then the generic .venv / venv probes. Assisted-by: Claude Code:claude-opus-5-5
Mikola Lysenko (mikolalysenko)
pushed a commit
that referenced
this pull request
Oct 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015S6JgBt7UbFe5cCPM9xbYp
This was referenced Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LLM Description written by Claude Code:claude-opus-5-5
Fixes #327
Fixes #329
Summary
scan --mode agentnow finds the virtualenv Poetry actually installed into in four cases it used to miss. In each case the scan had fallen back to the wrong interpreter, skipped the patch aspackage_not_installed, and exited 0:package-mode = falseproject;[project].nameand[tool.poetry].name;virtualenvs.in-project = falsenext to a stray./.venv;Changes, all in
crates/socket-patch-core/src/crawlers/python_crawler.rs:poetry_project_namesreturns candidates in poetry-core's order:[project].name(2.x), then[tool.poetry].name, thennon-package-mode. The first candidate that has a<name>-<hash>-py*dir on disk wins, so a Poetry 1.8 project (which ignores[project]) still finds its legacy-named env.find_local_venv_site_packagesasks Poetry's layered config first, followingEnvManager.use_in_project_venv: an explicitin-projectdecides, and only when it is unset does an existing./.venvcount. When Poetry wouldn't use./.venv, its out-of-tree env is probed before./.venvand./venv. Those stay as fallbacks when Poetry has no env.poetry_normalized_cwdgoes through the newwindows_normcase, which strips the\\?\/\\?\UNC\verbatim prefix as Python'srealpathdoes, then lowercases. Pipenv's path normalization now shares the samestrip_windows_verbatim_prefixhelper.docs/testing/poetry-compatibility.md("Mode notes") and a CHANGELOGFixedentry.The existing unit test
poetry_project_names_prefer_tool_poetry_and_return_both_spellingsasserted the old, wrong precedence. It is replaced bypoetry_project_names_follow_poetry_core_precedence.Root cause
find_poetry_virtualenv_site_packagesrebuilds Poetry's virtualenv location without running Poetry, and it differed from Poetry in three places:[tool.poetry].namefirst and had nonon-package-modefallback. poetry-core 2.x'sFactoryusesproject.get("name") or poetry_config.get("name", "non-package-mode"), and 1.9 useslocal_config.get("name", "non-package-mode")../.venvwin unconditionally, even when Poetry's config saidin-project = false.std::fs::canonicalize(cwd), which on Windows is\\?\C:\…. Poetry hashesnormcase(realpath(cwd)), which has no such prefix.Not in scope: the issues also point out that the scan exits 0 when the patch is skipped as
package_not_installed. That's how agent mode handles any package that isn't installed, not something specific to Poetry. With discovery fixed, the patch applies in each of these cases.Merge with v5 consolidation (#277), 2026-10-01
#277 landed on
mainand conflicted inpython_crawler.rsandCHANGELOG.md. Merge commitdf6cfba:find_local_venv_site_packages: kept this PR's Poetry-aware order.mainhad kept the old order, which probes.venv/venvfirst and Poetry only when they're empty, so takingmain's side would bring Agent-mode scan misses Poetry's venv for nameless non-package-mode projects, [project].name overrides, and in-project = false with a stray .venv, and still exits 0 #327 case 3 back. The doc comment was updated to match.CHANGELOG.md: added the Poetry entry tomain's consolidated### Fixedlist. The old NuGet<clear />entry on this branch is dropped becausemain's consolidated list already covers it.maincomputes Poetry env names.vendor/pypi_poetry.rs::load_poetry_projectis the lock/manifest reader and doesn't do venv discovery.Re-validation after the merge:
cargo test -p socket-patch-core --all-features --lib -- crawlers::python_crawler: 46 passed.cargo clippy --workspace --all-features -- -D warnings: clean.cargo fmt --all -- --check: this PR's code is clean.mainitself has many pre-existing rustfmt diffs (e.g.apply.rs,scan/*.rs), and CI doesn't run fmt.cargo test --workspace --all-features --no-fail-fast: 9328 passed, 12 failed. All 12 are sandbox-only write-failure or permission tests that fail because the sandbox runs as root (*_write_failure_*,*unremovable*,relax_loop_must_not_traverse_symlinked_root, …). None of them are in the crawler.GET https://pypi.org/pypi/six/1.16.0/json, because the binary's TLS stack doesn't trust the sandbox proxy CA (curl to the same URL returns 200). CI'se2e_vex_build poetry::legs passed ondf6cfbafor 1.0.10, 1.1.15, 1.8.5, 2.0.1 and 2.4.3 (Linux) and 2.4.3 (macOS).df6cfba: all 314 checks finished: success, apart from 4 that were skipped by design (e2e-docker,canary,downgrade, …). That includestest (ubuntu/macos/windows-latest),test-releaseandclippy. Bugbot's review ofdf6cfbafound no issues. No conflict withmain.Test evidence (original change)
mainpackage-mode = falsepoetry_project_names_follow_poetry_core_precedence,poetry_out_of_tree_virtualenvs_are_discovered_without_a_dot_venv(nameless step)[project].name+[tool.poetry].namepep-namestep)in-project = false+ stray.venvpoetry_out_of_tree_virtualenvs_are_discovered_without_a_dot_venv(in-project step)proj/.venv/...)\\?\hashwindows_normcase_drops_the_verbatim_prefix_like_python_realpath;#[cfg(windows)] poetry_normalized_cwd_has_no_verbatim_prefix_on_windowstest (windows-latest))poetry env use.find_local_venv_site_packagesreturned exactly the envpoetry env info -preports for the nameless, both-names andin-project = falseprojects.🤖 Generated with Claude Code
https://claude.ai/code/session_017mSDqYENPT34fbMjLSQzBg
Note
Medium Risk
Changes which Python site-packages agent mode targets for patching; mis-discovery would skip or mis-apply patches, though the change is read-only discovery with extensive regression tests.
Overview
Agent mode (
scan --mode agent) now locates Poetry’s real out-of-tree virtualenv in setups where discovery used to pick the wrong interpreter, skip patches aspackage_not_installed, and still exit 0.In
python_crawler.rs, venv probe order mirrors Poetry’sEnvManager.use_in_project_venv: when Poetry would not use./.venv(explicitvirtualenvs.in-project = false, or no in-project dir), Poetry’s cache env is checked before local./.venv/./venv, so stray local dirs from other tools no longer shadow Poetry’s install.Env naming follows poetry-core:
[project] name(2.x), then[tool.poetry] name, thennon-package-mode; the first candidate with a matching<name>-<hash>-py*directory wins (Poetry 1.8 still finds legacy-named envs).On Windows, cwd hashing strips the
\\?\verbatim prefix fromcanonicalize, matching Python’srealpath/normcase(shared helper with Pipenv path normalization).CHANGELOG and
docs/testing/poetry-compatibility.mddocument the behavior; unit/integration tests cover the #327/#329 cases.Reviewed by Cursor Bugbot for commit 50cde0a. Configure here.
Generated by Claude Code